<?php

namespace app\common\controller;

use think\Controller;
use Endroid\QrCode\QrCode;
use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\LabelAlignment;
use Endroid\QrCode\Response\QrCodeResponse;


class Ewm extends controller
{
    public function index($data){
        $dir = './uploads/ewm/'.date('Ymd').'/';
        $qrCode = new QrCode($data);

        $qrCode->setSize(300);
        $qrCode->setMargin(10);
        $qrCode->setEncoding('UTF-8');
        $qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH());
        $qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]);
        $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);
        $qrCode->setLabel("核销码：".$data, 11, null, LabelAlignment::CENTER());
        $qrCode->setLogoSize(100, 90);
        $qrCode->setValidateResult(false);
        if(is_dir($dir) === false){
            mkdir($dir);
        }
        $file = $dir.time().'.png';
        $qrCode->writeFile($file);
        return $file;

    }

}
